package com.example.sunmiv1.adapter;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.sunmiv1.R;
import com.example.sunmiv1.entity.StoreOrderInfo;
import com.example.sunmiv1.utils.Tools;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class StoreOrderAdapter extends BaseAdapter {

    private Context context;
    private List<StoreOrderInfo.DataBean> list;
    private ViewHolder viewHolder;

    public StoreOrderAdapter(Context context, List<StoreOrderInfo.DataBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.store_order_adapter, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        StoreOrderInfo.DataBean dataBean = list.get(position);
        viewHolder.orderNoStoreOrder.setText(dataBean.getOrder_no());
        viewHolder.orderTypeStoreOrder.setText(dataBean.getStatus_name());
        viewHolder.orderFromStoreOrder.setText(dataBean.getType_name());
        viewHolder.payTypeStoreOrder.setText(dataBean.getPay_name());
        viewHolder.salePeopleStoreOrder.setText(dataBean.getVip_name());
        viewHolder.totalStoreOrder.setText(dataBean.getAll_money());
        Tools.hideViewInItem(dataBean.getAdminname(),viewHolder.cashierStoreOrder);
        viewHolder.timeStoreOrder.setText(dataBean.getAdd_time());
        return convertView;
    }

    static
    class ViewHolder {
        @BindView(R.id.orderNo_storeOrder)
        TextView orderNoStoreOrder;
        @BindView(R.id.orderType_storeOrder)
        TextView orderTypeStoreOrder;
        @BindView(R.id.orderFrom_storeOrder)
        TextView orderFromStoreOrder;
        @BindView(R.id.payType_storeOrder)
        TextView payTypeStoreOrder;
        @BindView(R.id.salePeople_storeOrder)
        TextView salePeopleStoreOrder;
        @BindView(R.id.total_storeOrder)
        TextView totalStoreOrder;
        @BindView(R.id.cashier_storeOrder)
        TextView cashierStoreOrder;
        @BindView(R.id.time_storeOrder_)
        TextView timeStoreOrder;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
